package com.wms.controller;
import com.wms.dto.GoodsPageQueryDTO;
import com.wms.dto.StoragePageQueryDTO;
import com.wms.entity.WmsGoods;
import com.wms.entity.WmsStorage;
import com.wms.result.PageResult;
import com.wms.result.Result;
import com.wms.service.GoodsService;
import com.wms.service.StorageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")
@Slf4j
@Api(tags = "物品管理模块")
public class GoodsController{
    @Autowired
    private GoodsService goodsService;


    /**
     * 物品分页查询
     * @param goodsPageQueryDTO
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(@RequestBody GoodsPageQueryDTO goodsPageQueryDTO){
        PageResult pageResult = goodsService.page(goodsPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 物品仓库
     * @param wmsGoods
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增物品")
    public Result save(@RequestBody WmsGoods wmsGoods){
        log.info("新增物品:{}",wmsGoods);
        goodsService.save(wmsGoods);
        return Result.success();
    }

    /**
     * 物品仓库
     * @param wmsGoods
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改物品")
    public Result update(@RequestBody WmsGoods wmsGoods){
        goodsService.update(wmsGoods);
        return Result.success();
    }

    /**
     * 批量删除物品
     * @param ids
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("批量删除物品")
    public Result delete(@RequestParam List<Integer> ids){
        goodsService.delete(ids);
        return Result.success();
    }

    /**
     * 根据id查询物品
     * @param id
     * @return
     */
    @GetMapping("/getById/{id}")
    @ApiOperation("根据id查询物品")
    public Result getById(@PathVariable Long id){
        log.info("根据id查询仓库:{}",id);
        WmsGoods wmsGoods = goodsService.getById(id);
        return Result.success(wmsGoods);
    }

    @GetMapping("/getAll")
    @ApiOperation("查询所有物品")
    public Result getAll(){
        log.info("查询所有物品");
        List<WmsGoods> wmsGoods = goodsService.getAll();
        return Result.success(wmsGoods);
    }
}
